﻿// ***********************************************************************
// Assembly         : MVC4Portal (MyPrettyCMS)
// Author           : Lolo
// Created          : 10-21-2013
//
// Last Modified By : Lolo
// Last Modified On : 10-21-2013
// ***********************************************************************
// <copyright file="CountryController.cs" company="Innovacall">
//     Copyright (c) Innovacall. All rights reserved.
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web.Http;

namespace InnovaApp.Portals.MVC4Portal.Controllers
{
    /// <summary>
    /// Class CountryApiController.
    /// </summary>
    public class CountryController : ApiController
    {
        /// <summary>
        /// Countries the name contains.
        /// </summary>
        /// <param name="language">The language.</param>
        /// <param name="what">The what.</param>
        /// <returns>IEnumerable{System.String}.</returns>
        public IEnumerable<string> CountryNameContains(string language, object what)
        {
            List<string> toReturn = new List<string>();
            List<RegionInfo> list = new List<RegionInfo>();
            INNOVACALL.Framework.Common.MVCHelpers.Localization.CommonLocalization.SetCurrentThreadLanguage(language);
            foreach (var item in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures)) {
                try
                {
                    list.Add(new RegionInfo(item.Name));
                }
                catch (Exception){}
            }
            toReturn = list.Where(x => x.DisplayName.ToLower().Contains(what.ToString().Trim().ToLower())).Select(x => x.DisplayName).Distinct().Take(PortalEnvironment.DefaultAutoCompleateCount).ToList();
            return toReturn;
        }
    }
}
